// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/user/api/SysUserApi'

import ComClass from '@api/ComQuery'
import InfoClass from '@api/user/model/SysUserDto'
import EditClass from '@api/user/model/UpdateSortReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo(param, TIP = '查询信息') {
    const DTO = CORE.grpcDTO(InfoClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'sysUserQuery', DTO)
    return { list: resp.content || [] }
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  transEdit(one, { state: { info } }) {
    const userIdList = info.list.map((item) => item.id)
    return { userIdList }
  },
  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one)
    await CORE.grpc(TIP, CLIENT, 'updateSort', DTO)
    return CORE.grpcOK(TIP)
  },
}
